package com.googlecode.mysqlcommenter;

import java.io.File;
import java.io.FileWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

import com.googlecode.mysqlcommenter.model.Db;

public class Export {
   public void doExport(Db db, File file) throws Exception{
      /*  first, get and initialize an engine  */
      VelocityEngine ve = new VelocityEngine();
      ve.init();
      /*  next, get the Template  */

      Template t = ve.getTemplate( "template"+System.getProperty("file.separator")+"html.vm" );
      /*  create a context and add data */
      VelocityContext context = new VelocityContext();
      context.put("db", db);
      /* now render the template into a StringWriter */
      FileWriter writer = new FileWriter(file);
      t.merge( context, writer );
      writer.close();

   }

}
